package com.fengye.algorithms.leecode.dp;

/**
 * @Author fengye
 * @Date 2023/4/8 11:27
 **/
public class StockMaxProfitI121 {
    public int maxProfit(int[] prices) {
        if(prices.length<=1) {
            return 0;
        }
        int max = 0;
        // 找到最小价格前的价格i没有意义
        int minPrice = prices[0];
        for(int i=0;i<prices.length;i++) {
            if(prices[i] < minPrice) {
                minPrice = prices[i];
            }
            if(prices[i] - minPrice > max) {
                max = prices[i] - minPrice;
            }
        }
        return max;
    }
}
